fixing links

jamesperet 11 years ago
parent
commit
8fbfc8ad6f

+ 34 - 1
app/controllers/agent_controller.rb

@@ -1,14 +1,47 @@
1 1
 class AgentController < ApplicationController
2 2
   
3
+  layout 'front_end'
4
+  
3 5
   def current_missions
4 6
     
5 7
   end
6 8
 
7 9
   def choose_mission
8
-    
10
+    @user = User.find(current_user.id)
11
+    @mission_invites = @user.mission_agent_invites.where(:status => 'invited')
9 12
   end
10 13
 
11 14
   def agent_profile
12 15
       @user = User.find(params[:id])
13 16
   end
17
+  
18
+  def accept_mission
19
+    @user = User.find(current_user.id)
20
+    @mission_invite = @user.mission_agent_invites.find(params[:id])
21
+    @mission_invite.status = 'accepted'
22
+    respond_to do |format|
23
+      if @mission_invite.save
24
+        format.html { redirect_to mission_choose_path, notice: 'Mission was accepted.' }
25
+        format.json { head :no_content }
26
+      else
27
+        format.html { redirect_to mission_choose_path, notice: 'Mission was not accepted. Please try again later.' }
28
+        format.json { render json: @mission.errors, status: :unprocessable_entity }
29
+      end
30
+    end
31
+  end
32
+  
33
+  def denie_mission
34
+    @user = User.find(current_user.id)
35
+    @mission_invite = @user.mission_agent_invites.find(params[:id])
36
+    @mission_invite.status = 'denied'
37
+    respond_to do |format|
38
+      if @mission_invite.save
39
+        format.html { redirect_to mission_choose_path, notice: 'Mission was denied.' }
40
+        format.json { head :no_content }
41
+      else
42
+        format.html { redirect_to mission_choose_path, notice: 'Mission was not denied. Please try again later.' }
43
+        format.json { render json: @mission.errors, status: :unprocessable_entity }
44
+      end
45
+    end
46
+  end
14 47
 end

+ 2 - 0
app/models/user.rb

@@ -3,4 +3,6 @@ class User < ActiveRecord::Base
3 3
   # :confirmable, :lockable, :timeoutable and :omniauthable
4 4
   devise :database_authenticatable, :registerable,
5 5
          :recoverable, :rememberable, :trackable, :validatable
6
+         
7
+  has_many :mission_agent_invites
6 8
 end

+ 22 - 2
app/views/agent/choose_mission.html.erb

@@ -1,2 +1,22 @@
1
-<h1>Agent#choose_mission</h1>
2
-<p>Find me in app/views/agent/choose_mission.html.erb</p>
1
+<div class="page-header">
2
+  <h1>Choose your Missions </h1>
3
+</div>
4
+<ul class="thumbnails">
5
+<% @mission_invites.each do |invite| %>
6
+	<li class="span4">
7
+		    <div class="thumbnail" style= "padding: 5px;">
8
+		      <h3 style= "padding: 5px;"><%= invite.mission_agent.mission.title %></h3>
9
+		      <p style= "padding: 5px; height: 50px;"><%= invite.mission_agent.mission.description %></p>
10
+			 <div style="width: 48%; float: left;">
11
+				 <%= link_to 'accept', mission_agent_accept_path(invite.id), :class => "btn btn-large btn-block btn-success" %>
12
+			 </div>
13
+			 <div style="width: 48%; float: right;">
14
+			 	<%= link_to 'Denie', mission_agent_denie_path(invite.id), :class => "btn btn-large btn-block btn-danger" %>
15
+			 </div>
16
+			 <div class="clearfix"></div>
17
+		    </div>
18
+		  
19
+		
20
+	</li>
21
+<% end %>
22
+</ul>

+ 1 - 0
app/views/layouts/partials/_nav_links.html.erb

@@ -1,6 +1,7 @@
1 1
 <ul class="nav">
2 2
    <% if user_signed_in? %>
3 3
    	<li><%= link_to "Missions", missions_path  %></li>
4
+	<li><%= link_to "Choose Missions", mission_choose_path  %></li>
4 5
    <% else %>
5 6
    	<li><%= link_to "About", start_about_path  %></li>
6 7
    	

+ 3 - 1
config/routes.rb

@@ -1,7 +1,9 @@
1 1
 AvalancheGame::Application.routes.draw do
2 2
   get "start/about"
3 3
   get "agent/current_missions"
4
-  get "agent/choose_mission"
4
+  get "choose_missions" => "agent#choose_mission", :as => :mission_choose
5
+  get "accept_mission/:id" => "agent#accept_mission", :as => :mission_agent_accept
6
+  get "denie_mission/:id" => "agent#denie_mission", :as => :mission_agent_denie
5 7
   get "agent/:id" => "agent#agent_profile"
6 8
   
7 9
   get "missions/:id/launch" => "missions#launch", :as => :mission_launch